class_name HealthComponent
extends Node

signal died
signal damaged
signal health_changed(current_health: float, max_health: float)



@export var max_health: float = 1
var _current_health: float
var current_health: float:
	get:
		return _current_health
	set(value):
		_current_health = value
		health_changed.emit(_current_health, max_health)




func _ready() -> void:
	current_health = max_health


func damage(amount: float):
	current_health = clamp(current_health - amount, 0.0, max_health)
	damaged.emit()
	if current_health <= 0.0:
		died.emit()




func reset_health(context_max_health:float = max_health) -> void:
	max_health = context_max_health
	current_health = max_health
